/*
    * Author:   Sander
    * Date:     13-mei-2011
    * Name:     Image
    * Version:  1.0
    *
    * This code is property of Sander blahblahblah copyright blahblah.
*/


package javaraytracer.Materials;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

//PENDING:add function/property description
public class Image
{

	private BufferedImage _image;
	public int imageWidth = 0;
	public int imageHeight = 0;
	public int[][] data;

	public Image(String file)
	{
		load(file);
	}

	private void load(String file)
	{
		try
		{
			_image = ImageIO.read(new File(file));
			imageWidth = _image.getWidth();
			imageHeight = _image.getHeight();
			data = new int[imageHeight][imageWidth];
			for(int y = 0; y < imageHeight; y++)
			{
				for(int x = 0; x < imageWidth; x++)
				{
					data[y][x] = _image.getRGB(x, y);
				}
			}
		}
		catch(IOException e)
		{
			imageWidth = 0;
			imageHeight = 0;
			data = new int[0][0];
			
			System.out.println(e + "\n" + file);
		}
	}
}
